package grape.crm.rest.customercontact.mapper;

import grape.crm.rest.customercontact.form.CustomerContactAttrCreateForm;
import grape.crm.service.customercontact.param.AddCustomerContactParam;
import grape.crm.service.customercontact.po.CustomerContact;
import grape.common.rest.mvc.WebMapper;
import org.mapstruct.Mapper;
import grape.crm.rest.customercontact.form.CustomerContactCreateForm;
import grape.crm.rest.customercontact.form.CustomerContactUpdateForm;
import grape.crm.rest.customercontact.form.CustomerContactListPageForm;
import grape.crm.rest.customercontact.vo.CustomerContactVo;
import org.mapstruct.ReportingPolicy;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 客户联系方式表 前端领域模型映射
 * </p>
 *
 * @author yangwei
 * @since 2020-09-14
 */
@Mapper(componentModel = "spring",unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CustomerContactWebMapper extends WebMapper<CustomerContactVo, CustomerContact> {

    CustomerContact formToPo(CustomerContactCreateForm f);
    CustomerContact formToPo(CustomerContactUpdateForm f);
    CustomerContact formToPo(CustomerContactListPageForm f);

    AddCustomerContactParam formToParam(CustomerContactCreateForm f);
    AddCustomerContactParam formToParam(CustomerContactAttrCreateForm f);

    default List<AddCustomerContactParam> createFormsToParams(List<CustomerContactCreateForm> forms) {
        if (forms == null) {
            return null;
        }
        return forms.stream().map(this::formToParam).collect(Collectors.toList());
    }
    default List<AddCustomerContactParam> attrCreateFormsToParams(List<CustomerContactAttrCreateForm> forms) {
        if (forms == null) {
            return null;
        }
        return forms.stream().map(this::formToParam).collect(Collectors.toList());
    }
}
